package de.karnik.dokobu.persistence;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Queries;
import javax.jdo.annotations.Query;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable( identityType = IdentityType.APPLICATION, detachable="true" )
@Queries( {
	@Query( name="Ingredient_GetByName", language="JDOQL", 
			value="SELECT FROM de.karnik.dokobu.persistence.Ingredient WHERE name == :1" ),
	@Query( name="Ingredient_SearchByName", language="JDOQL", 
			value="SELECT FROM de.karnik.dokobu.persistence.Ingredient WHERE name >= :1 && name < :2" )
} )
public class Ingredient { 
	
    @PrimaryKey
    @Persistent( valueStrategy = IdGeneratorStrategy.IDENTITY )
	private Key id;
    @Persistent
	private String name;
    @Persistent( dependent="true" )
    private IngredientIndex index;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Key getId() {
		return id;
	}

	public void setIndex(IngredientIndex index) {
		this.index = index;
	}

	public IngredientIndex getIndex() {
		return index;
	}
	 
}
